/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-06-09 09:49:40
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-09-25 14:40:01
 * @FilePath: \linePatrol\vue-element-plus-admin\src\store\modules\plangroup.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { UserListAlltype } from '@/api/department/types'
import PlanGroupApi from '@/api/linePatrol/PlanGroupApi'
import {
  FacTaskListType,
  ScheduleSendTaskDetailType,
  SendTasklistType
} from '@/api/linePatrol/type'
import { defineStore } from 'pinia'
import { store } from '../index'
import GetSystemUserApi from '@/api/department/UserApi'
import SetSecurCheckApi from '@/api/securcheck/SetSecurCheck'
interface Group {
  uuid: string
  qrCode: string
  facilityCode: string
  faciId: number
  facDictType: string
  facState: string
  facName: string
  coId: number
  deptId: number
  squadId: number
  userId: number
  operationDate: string
  redType: string
  isDeadFac: string
  roadName: string
  esuName: string
  esuDate: string
  mcMaterial: string
  isUmale: string
  pipeDropNo: number
  address: string
  notes: string
  isCoAs: string
  factoryStation: number
  file: string
  facOutUuid: string
  facOutModel: string
  facOutNo: number
  producerUuid: string
  facOutStartDate: string
  facOutAge: number
  facOutEndDate: string
  pipeNetId: number
  surveyLocUuid: string
  userAreaId: number
  material: string
  guardrail: string
  controlledArea: string
}
interface GroupState {
  code: number
  msg: string
  rows: Group[]
  total: number
}
export const usePatrolGroupStore = defineStore('grop', {
  state: () => {
    return {
      GroupData: {} as GroupState,
      GroupDataID: undefined as number | undefined,
      LssuePlanID: '' as SendTasklistType | undefined,
      IssueUserID: '' as SendTasklistType | undefined,
      IssueCustomerUnitID: '' as SendTasklistType | undefined,
      FacTaskListAll: [] as unknown as FacTaskListType[],
      UserListAll: [] as unknown as UserListAlltype[],
      ScheduleSendTaskDetail: {} as ScheduleSendTaskDetailType,
      activeName: '0' as string | undefined
    }
  },
  getters: {
    getGroupData(): GroupState {
      return this.GroupData
    },
    getFacTaskListAll(): FacTaskListType[] {
      return this.FacTaskListAll
    },
    getUserListAll(): UserListAlltype[] {
      return this.UserListAll
    },
    getScheduleSendTaskDetail(): ScheduleSendTaskDetailType {
      return this.ScheduleSendTaskDetail
    }
  },
  actions: {
    setGroupData(Data: GroupState) {
      this.GroupData = Data
    },
    setGroupDataID(id: number | undefined) {
      this.GroupDataID = id
    },
    SetLssuePlanID(id: any | undefined) {
      this.LssuePlanID = id
    },
    SetIssueUserID(id: any | undefined) {
      this.IssueUserID = id
    },
    SetIssueCustomerUnitID(id: any | undefined) {
      this.IssueCustomerUnitID = id
    },
    async setFacTaskList(groupUserCom: number) {
      if (groupUserCom == 3) {
        this.FacTaskListAll = await PlanGroupApi.FacTaskListAll() //获取巡查组 所有列表
      } else {
        this.FacTaskListAll = await SetSecurCheckApi.GetAllGroupList({ groupUserCom: groupUserCom }) //获取巡查组 所有列表
      }
    },
    async setUserListAll() {
      this.UserListAll = await GetSystemUserApi.GetAllUser() //获取巡查组 所有列表
    },
    async setScheduleSendTaskDetail(uuid: string | undefined, groupUserCom: number) {
      if (groupUserCom == 3) {
        this.ScheduleSendTaskDetail = await PlanGroupApi.GetScheduleSendTask(uuid)
        if (this.ScheduleSendTaskDetail) {
          this.activeName = this.ScheduleSendTaskDetail.planType
        }
      } else {
        this.ScheduleSendTaskDetail = await SetSecurCheckApi.GetScheduleSecurTask(uuid)
        if (this.ScheduleSendTaskDetail) {
          this.activeName = this.ScheduleSendTaskDetail.planType
        }
      }
    }
  },
  persist: true
})

export const useLockStoreWithOut = () => {
  return usePatrolGroupStore(store)
}
